package jxust.isp4mn.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jxust.isp4mn.model.TestModel;
import jxust.isp4mn.service.TestService;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

@Component("testAction")
@Scope("prototype")
public class TestAction extends ActionSupport implements ServletRequestAware,ServletResponseAware{

	private HttpServletRequest request;
	private HttpServletResponse response;
	private HttpSession session;
	
	private TestModel test;
	private List<TestModel> tests;
	
	@Resource
	private TestService testService;
	
	@Override
	public String execute(){
		return null;
	}
	
	public String add(){
		testService.add(test);
		request.setAttribute("testWord", test);
		session.setAttribute("testWord", test);
		
		tests = testService.findAll();
		
		return SUCCESS;
	}
	
	public String findAll(){
		tests = testService.findAll();
		return SUCCESS;
	}

	public TestModel getTest() {
		return test;
	}

	public void setTest(TestModel test) {
		this.test = test;
	}

	public List<TestModel> getTests() {
		return tests;
	}

	public void setTests(List<TestModel> tests) {
		this.tests = tests;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
		this.session = this.request.getSession();
		
	}

	public void setServletResponse(HttpServletResponse arg0) {
		this.response = arg0;
	}
}
